export const summaryHelper = (param: any, columnsJson: Object, summaryname: string) => {
    const { columns, data } = param
    const sums= []
    const has = columns.some((it) => columnsJson[it.property] && (columnsJson[it.property]['stats'] || columnsJson[it.property]['sum'] || columnsJson[it.property]['avg']))
    columns.forEach((column, index) => {
        const it = columnsJson[column.property];
        if(has && it){
            if (index === 2) {
                // sums[index] = summaryname ?? (it['stats'] === true ? '统计' : (it['stats'] ?? (it['sum'] || it['avg'])))
                sums[index] = summaryname || '统计'
            }else
            if (index > 2) {
                if (it['sum']) {
                    sums[index] = sumFun(data, column, index)
                } else if (it['avg']) {
                    sums[index] = avgFun(data, column, index)
                }
            }else{
                sums[index] = ''
            }
        }
    })
    return sums
}

const sumFun = (data, column, index)=>{
    if(index == 2) return
    const values = data.map((item) => Number(item[column.property]))
    let sum = ''
    // Number.isNaN(value)) 判断value是否是数值类
    if (!values.every((value) => Number.isNaN(value))) {
        sum = `${values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!Number.isNaN(value)) {
                return prev + curr
            } else {
                return prev
            }
        }, 0)}`
    }
    return sum
}


const avgFun = (data, column, index)=>{

}
